package blackjack;

import java.util.ArrayList;
import java.util.Scanner;

public class Player {
	Scanner in = new Scanner(System.in);

	int money;
	String name;
	Deck deck;
	boolean isSticking = false;

	ArrayList<Hand> hand = new ArrayList<Hand>();

	public Player(Hand newHand, int startingMoney, String name, Deck deck) {
		hand.add(newHand);
		this.money = startingMoney;
		this.name = name;
		this.deck = deck;
	}

	public int bet(int amount) {
		if (money > amount) {
			money -= amount;
			if (money == 0)
				System.out.println(name + " is going all in.");
			return money;
		} else {
			System.out.println("You don't have enough money for that bet");
			return -1;
		}

	}

	public boolean isSticking() {
		return isSticking;
	}

	public String toString() {
		String ret = "";
		for (int i = 0; i < hand.size(); i++) {
			ret += name + "'s hand is: " + hand.get(i).toString();
			if (hand.size() > 1) {
				ret += " " + name + "'s other hand is: ";
			}
		}
		return ret;
	}

	public void play() {
		System.out.println("What would you like to do? [H]it or [S]tick?");
		String choice = in.nextLine().toUpperCase();
		char c = choice.charAt(0);
		switch (c) {
		case 'H':
			hand.get(0).addCard(deck.hit());
			System.out.println(hand.get(0));
			break;
		case 'S':
			isSticking = true;
			break;
		default:
			break;
		// TODO Auto-generated method stub

		}

	}

	public boolean isBusted() {
		// TODO Auto-generated method stub
		return hand.get(0).isBusted();
	}
}
